package festival.game;

import festival.input.Action;
import festival.input.Alert;
import festival.input.InputListener;
import festival.main.MainFrame;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class GameRunner {
    
	private MainFrame mMainFrame;
	private GameFrame mGameFrame;
    private GameCaretaker mCaretaker;
    private Game mGame;
//    private GameView mGameView;
//    private GameLoader mGameLoader;
    
    public void updateGameView() {
        // mGameView.setGame(mCaretaker.getCurrentState());
    }
    
    public GameRunner() {
//    	BoardView view = new BoardView(new Board(sJavaMap));
        
//        mMainFrame = new MainFrame();
//        mMainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
////        mMainFrame.getContentPane().add(view);
//        mMainFrame.setVisible(true);
        
        
    }
    
    public void runNewGame(int numPlayers) { 
    	mGame = new Game(numPlayers);
    	mGameFrame = new GameFrame(mGame);
    	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    	mGameFrame.setBounds(screenSize.width / 8, screenSize.height / 8,
    	        screenSize.width * 3 / 4, screenSize.height * 3 / 4);
    	initMenus();
        mGameFrame.setVisible(true);
        
//        InputListener l = new InputListener(KeyEvent.VK_1, new Action() {
//            public void doAction() {
//                System.out.println("yes");
//            }
//        });
//        InputListener n = new InputListener(KeyEvent.VK_2, new Action() {
//            public void doAction() {
//                System.out.println("no");
//            }
//        });
//        InputListener m = new InputListener(KeyEvent.VK_3, new Action() {
//            public void doAction() {
//                System.out.println("no");
//            }
//        });
//        InputListener q = new InputListener(KeyEvent.VK_3, new Action() {
//            public void doAction() {
//                System.out.println("no");
//            }
//        });
//        Alert a = new Alert("This is a test.", "Test", 
//                new String[] {"OK", "Fuck you", "BALLS", "l"}, new InputListener[] { l, n, m, q });
//        a.show();
        
//    	mCaretaker = new GameCaretaker(mGame);
//    	mGameView = new GameView(mGame);
    }
    
    private void initMenus() {
		JMenuBar menuBar = new JMenuBar();
		JMenu gameMenu = new JMenu("Game");
		JMenu newGameMenu = new JMenu("New Game");
		JMenuItem newGame2Players = new JMenuItem("2 Players");
		newGame2Players.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				runNewGame(2);
			}

		});
		newGameMenu.add(newGame2Players);
		JMenuItem newGame3Players = new JMenuItem("3 Players");
		newGame3Players.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				runNewGame(3);
			}

		});
		newGameMenu.add(newGame3Players);
		JMenuItem newGame4Players = new JMenuItem("4 Players");
		newGame4Players.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				runNewGame(4);
			}

		});
		newGameMenu.add(newGame4Players);
		gameMenu.add(newGameMenu);
		
		JMenuItem loadGame = new JMenuItem("Load Game");
		// add actionListener to loadGame
		gameMenu.add(loadGame);
		
		menuBar.add(gameMenu);

		mGameFrame.setJMenuBar(menuBar);
	}
}
